package com.open.rbac.constant;

import java.util.Arrays;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

import com.open.center.common.constant.Enumerator;
import com.open.center.jpa.converter.DbEnumConverter;


/**
 * 布尔值常量
 * Y - 是
 * N - 否
 */
@Getter
public enum BooleanType implements Enumerator<BooleanType, String> {

    YES("Y", "是"),

    NO("N", "否");

    private final String id;

    @JsonValue
    private final String name;

    BooleanType(String id, String name) {
        this.id = id;
        this.name = name;
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static BooleanType as(@JsonProperty("id") String id) {
        return Arrays.stream(BooleanType.values())
                .filter(e -> e.getId().equals(id))
                .findAny()
                .orElse(null);
    }

    public static class Converter extends DbEnumConverter<BooleanType, String> {
        public Converter() {
            super(BooleanType.class);
        }
    }
}
